package com.qf.shop.controller;

import com.qf.shop.annotation.ProcessInfo;
import com.qf.shop.entity.Pay;
import com.qf.shop.mapper.PayMapper;
import com.qf.shop.model.Results;
import com.qf.shop.model.TableData;
import com.qf.shop.pojo.QueryPay;
import com.qf.shop.service.IPayService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@Transactional
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/pay")
public class PayController {

    private IPayService PayService;

    public PayController(IPayService payServiceImpl) {
        this.PayService = payServiceImpl;
    }


    @GetMapping
    @ProcessInfo("查询所有订单支付数据")
    public TableData<Pay> getAllPay(QueryPay queryPay,
                                    @RequestParam(defaultValue = "0") Integer offset,
                                    @RequestParam(defaultValue = "10") Integer limit){

        TableData<Pay> allPay = PayService.getAllPay(queryPay, offset, limit);
        return allPay;
    }

    @DeleteMapping("/{id}")
    @ProcessInfo("删除订单数据")
    public Results deletePayUser(@PathVariable("id") Integer id){
        Results results = new Results();

        try{
            PayService.deletePayById(id);
            results.setCode(1);
            results.setMsg("success");
        }catch (Exception e){
            e.printStackTrace();
            results.setCode(-1);
            results.setMsg("fail");
        }
        return results;
    }

}
